import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useMailVerifyStore = defineStore('mailVerify', () => {
  const isVerifying = ref(false)
  const countdown = ref(60)
  const newVerifiedMail = ref(null)

  const startCountdown = () => {
    // 倒數計時
    isVerifying.value = true
    const timer = setInterval(() => {
      countdown.value--
      if (countdown.value <= 0) {
        isVerifying.value = false
        countdown.value = 60
        clearInterval(timer)
      }
    }, 1000)
  }

  return {
    isVerifying,
    countdown,
    newVerifiedMail,
    startCountdown,
  }
})
